package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioGroup;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class RadioBtn extends AppCompatActivity {

    private RadioGroup radio_group;

    private ImageView image_view;
    private int[] images;
    private Button btn_xuanzou;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_radio_btn);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        btn_xuanzou = findViewById(R.id.button_xuanzuo1);
        btn_xuanzou.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(),Selectseat.class);
                startActivity(intent);
            }
        });


        images = new int[]{R.drawable.changjh,R.drawable.nezha2,R.drawable.ershi,R.drawable.fengshen,R.drawable.gongfu};

        image_view = findViewById(R.id.imageView);

        radio_group = findViewById(R.id.radiogroup);
        radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId==R.id.radioButton1){
                    image_view.setImageResource(images[0]);
                } else if (checkedId==R.id.radioButton2){
                    image_view.setImageResource(images[1]);
                }else if (checkedId==R.id.radioButton3){
                    image_view.setImageResource(images[2]);
                }else if (checkedId==R.id.radioButton4){
                    image_view.setImageResource(images[3]);
                }else if (checkedId==R.id.radioButton5){
                    image_view.setImageResource(images[4]);
                }


            }
        });
    }
}